package com.zzyl.controller.customer;

import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ReservationDto;
import com.zzyl.dto.ReservationQueryDto;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController {

    @Autowired
    ReservationService reservationService;

    @ApiOperation("查询取消预约数量")
    @GetMapping("/cancelled-count")
    public ResponseResult<Integer> getCancelledCount() {
        log.info("查询取消预约数量");
        return ResponseResult.success(reservationService.getCancelledCount());
    }

    @ApiOperation("查询每个时间段剩余预约次数")
    @GetMapping("/countByTime")
    public ResponseResult<List<TimeCountVo>> getCountByTime(Long time) {
        log.info("查询每个时间段剩余预约次数");
        return ResponseResult.success(reservationService.getCountByTime(time));
    }

    @ApiOperation("新增预约")
    @PostMapping
    public ResponseResult<Void> addReservation(@RequestBody ReservationDto Dto) {
        log.info("新增预约");
        reservationService.add(Dto);
        return ResponseResult.success();
    }

    @ApiOperation("分页查询预约")
    @GetMapping("/page")
    public ResponseResult<PageBean<ReservationVo>> getReservationPage(ReservationQueryDto dto) {
        log.info("分页查询预约");
        PageBean<ReservationVo> pageBean = reservationService.findByPage(dto);
        return ResponseResult.success(pageBean);
    }

    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public ResponseResult<Void> cancelReservation(@PathVariable Long id) {
        log.info("取消预约");
        reservationService.cancelReservation(id);
        return ResponseResult.success();
    }
}
